2020-2021 Sunseeker Telemetry and Lighting System
adc10_a_ex8_sequenceDMA.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
45 //1
71 //******************************************************************************
72 
73 
74 void main (void)
75 {
76 
77  //8-bit ADC conversion result array
78  uint8_t ADC_Result[3];
79 
80  //Stop Watchdog Timer
81  WDT_A_hold(WDT_A_BASE);
82 
83  //Initialize the ADC10_A Module
84  /*
85  * Base Address for the ADC10_A Module
86  * Use internal ADC10_A bit as sample/hold signal to start conversion
87  * USE MODOSC 5MHZ Digital Oscillator as clock source
88  * Use default clock divider of 1
89  */
90  ADC10_A_init(ADC10_A_BASE,
91  ADC10_A_SAMPLEHOLDSOURCE_SC,
92  ADC10_A_CLOCKSOURCE_ADC10OSC,
93  ADC10_A_CLOCKDIVIDER_1);
94 
95  ADC10_A_enable(ADC10_A_BASE);
96 
97  /*
98  * Base Address for the ADC10_A Module
99  * Sample/hold for 16 clock cycles
100  * Enable Multiple Sampling
101  */
102  ADC10_A_setupSamplingTimer(ADC10_A_BASE,
103  ADC10_A_CYCLEHOLD_16_CYCLES,
104  ADC10_A_MULTIPLESAMPLESENABLE);
105  //Change the resolution to 8-bit
106  ADC10_A_setResolution(ADC10_A_BASE,
107  ADC10_A_RESOLUTION_8BIT);
108 
109  //Configure Memory Buffer
110  /*
111  * Base Address for the ADC10_A Module
112  * Use input A2
113  * Use positive reference of AVcc
114  * Use negative reference of AVss
115  */
116  ADC10_A_configureMemory(ADC10_A_BASE,
117  ADC10_A_INPUT_A2,
118  ADC10_A_VREFPOS_AVCC,
119  ADC10_A_VREFNEG_AVSS);
120 
121 
122  //Initialize and Setup DMA Channel 0
123  /*
124  * Configure DMA channel 0
125  * Configure channel for repeated single transfer
126  * DMA interrupt flag will be set after every 3 transfers
127  * Use DMA Trigger Source 24 (ADC10IFG)
128  * Transfer Byte-to-byte
129  * Trigger upon the Rising Edge of the Trigger Source
130  */
131  DMA_initParam param = {0};
132  param.channelSelect = DMA_CHANNEL_0;
133  param.transferModeSelect = DMA_TRANSFER_REPEATED_SINGLE;
134  param.transferSize = 3;
135  param.triggerSourceSelect = DMA_TRIGGERSOURCE_24;
136  param.transferUnitSelect = DMA_SIZE_SRCBYTE_DSTBYTE;
137  param.triggerTypeSelect = DMA_TRIGGER_RISINGEDGE;
138  DMA_init(&param);
139  /*
140  * Configure DMA channel 0
141  * Use ADC10_A Memory Buffer as source
142  * Increment destination address after every transfer
143  */
144  DMA_setSrcAddress(DMA_CHANNEL_0,
145  ADC10_A_getMemoryAddressForDMA(ADC10_A_BASE),
146  DMA_DIRECTION_UNCHANGED);
147  /*
148  * Base Address of the DMA Module
149  * Configure DMA channel 0
150  * Use ADC_Result[0] as destination
151  * Increment destination address after every transfer
152  */
153  DMA_setDstAddress(DMA_CHANNEL_0,
154  (uint32_t)(uintptr_t)&ADC_Result[0],
155  DMA_DIRECTION_INCREMENT);
156 
157  //Enable DMA channel 0 interrupt
158  DMA_clearInterrupt(DMA_CHANNEL_0);
159  DMA_enableInterrupt(DMA_CHANNEL_0);
160 
161  //Enable transfers on DMA channel 0
162  DMA_enableTransfers(DMA_CHANNEL_0);
163 
164  while (1)
165  {
166  //Wait if ADC10_A core is active
167  while (ADC10_A_isBusy(ADC10_A_BASE)) ;
168 
169  //Enable and Start the conversion
170  //in Sequence of Channels Conversion Mode
171  ADC10_A_startConversion(ADC10_A_BASE,
172  ADC10_A_SEQOFCHANNELS);
173 
174  //LPM0, ADC10_A_ISR will force exit
175  __bis_SR_register(CPUOFF + GIE);
176  //Delay between sequence convs
177  __delay_cycles(5000);
178  //BREAKPOINT; check ADC_Result
179  __no_operation();
180  }
181 }
182 
183 // DMA interrupt service routine
184 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
185 __interrupt
186 #elif defined(__GNUC__)
187 __attribute__((interrupt(DMA_VECTOR)))
188 #endif
189 void DMA0_ISR (void) {
190  switch (__even_in_range(DMAIV,16)){
191  case 0: break; //No interrupt
192  case 2: //DMA0IFG
193  //Sequence of Channels Conversion Complete
194  //exit LPM
196  break;
197  case 4: break; //DMA1IFG
198  case 6: break; //DMA2IFG
199  default: break;
200  }
201 }
202 
MPU_initThreeSegmentsParam param
void main(void)
void DMA0_ISR(void)
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
__delay_cycles(500000)